﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace WebApplication1
{
    public partial class ordcd : System.Web.UI.Page
    {
        SqlConnection cnn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
        string ono, no;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.Items.Add("English");
                DropDownList1.Items.Add("Hindi");
                DropDownList1.Items.Add("Kannada");
            }
            cnn.Open();
            SqlCommand cmd = new SqlCommand("select top 1 ordno from ordcd order by ordno desc", cnn);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows == false)
                txtordno.Text = "100";
            else
            {
                while (dr.Read())
                {
                    ono = Convert.ToString(Convert.ToUInt32(dr.GetValue(0)) + 1);
                    txtordno.Text = ono;
                }
            }
            cnn.Close();
        }

        protected void btnord_Click(object sender, EventArgs e)
        {
            no = Convert.ToString(Session["no"]);
            cnn.Open();
            SqlCommand cmd = new SqlCommand("insert into ordcd values('" + txtordno.Text + "','" + no + "','" + DropDownList1.SelectedItem+"','" + txtcdname.Text + "','" + txtpub.Text + "','" + txtyr.Text + "')", cnn);
            cmd.ExecuteNonQuery();
            cnn.Close();
            Response.Redirect("ordcd.aspx");
        }
    }
}